﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

namespace Simhopp.Common
{
    public class MyLogger
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// Writes a debug message to the appenders specified in the app.config file
        /// </summary>
        /// <param name="message">Message to be logged</param>
        public static void Debug(String message)
        {
            if (log.IsDebugEnabled)
            {
                var callingMethod = new StackTrace().GetFrame(1).GetMethod();
                var name = callingMethod.ReflectedType.Name;
                log.Debug(String.Format("{0} - {1}", name, message));
            }
        }

        /// <summary>
        /// Writes a Info message to the appenders specified in the app.config file
        /// </summary>
        /// <param name="message">Message to be logged</param>
        public static void Info(String message)
        {
            if (log.IsInfoEnabled)
            {
                var callingMethod = new StackTrace().GetFrame(1).GetMethod();
                var name = callingMethod.ReflectedType.Name;
                log.Info(String.Format("{0} - {1}", name, message));
            }
        }

        /// <summary>
        /// Writes a warn message to the appenders specified in the app.config file
        /// </summary>
        /// <param name="message">Message to be logged</param>
        public static void Warn(String message)
        {
            if (log.IsWarnEnabled)
            {
                var callingMethod = new StackTrace().GetFrame(1).GetMethod();
                var name = callingMethod.ReflectedType.Name;
                log.Warn(String.Format("{0} - {1}", name, message));
            }
        }

        /// <summary>
        /// Writes a error message to the appenders specified in the app.config file
        /// </summary>
        /// <param name="message">Message to be logged</param>
        public static void Error(String message)
        {
            if (log.IsErrorEnabled)
            {
                var callingMethod = new StackTrace().GetFrame(1).GetMethod();
                var name = callingMethod.ReflectedType.Name;
                log.Error(String.Format("{0} - {1}", name, message));
            }
        }

        /// <summary>
        /// Writes a fatal message to the appenders specified in the app.config file
        /// </summary>
        /// <param name="message">Message to be logged</param>
        public static void Fatal(String message)
        {
            if (log.IsFatalEnabled)
            {
                var callingMethod = new StackTrace().GetFrame(1).GetMethod();
                var name = callingMethod.ReflectedType.Name;
                log.Fatal(String.Format("{0} - {1}", name, message));
            }
        }
    }
}
